const SEARCH_CONST = 'search';
const EXPORT_CONST = 'export';

const DATATYPE_ALL = '1'; // 导出时，查询所有
const DATATYPE_REQUIREMENTS = '2'; // 导出时，按条件查询
const DATATYPE_CURRENTPAGE = '3'; // 导出时，导出当前页

/**
 * 构建查询条件
 * @param table_const
 * @param params
 */
export function createSearchParams(table_const, params){
  var data = {};

  for(var key in table_const) {
    if(table_const[key]['isSearch']) {
      let tempParams = table_const[key];
      if(table_const[key]['searchType'] == 'timeToTime') {
        data[tempParams['searchColFieldName'][0]] = params[tempParams['searchColFieldName'][0]] ? params[tempParams['searchColFieldName'][0]]: '';
        data[tempParams['searchColFieldName'][1]] = params[tempParams['searchColFieldName'][1]] ? params[tempParams['searchColFieldName'][1]]: '';
      }else{
        data[tempParams['searchColFieldName']] = params[tempParams['searchColFieldName']] ? params[tempParams['searchColFieldName']]: '';
      }
    }
  }

  if(params['searchOrExport'] == SEARCH_CONST){
    data['pageno'] = params['pageno'];
    data['pagesize'] = params['pagesize'];
  }else{
    if(params['dataType'] == DATATYPE_ALL) {
      data = {};
    }
    else if(params['dataType'] == DATATYPE_REQUIREMENTS) {
      data['pageno'] = 0;
      data['pagesize'] = 0;
    }
    else {
      data['pageno'] = params['pageno'];
      data['pagesize'] = params['pagesize'];
    }
    data['isExport'] = true;
  }

  return data;
}

